using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using FShop.DAL;
using FShop.BAL;

public partial class ProdutcDetail : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            string product_ID = Request.QueryString["Product_ID"];

            if (!string.IsNullOrEmpty(product_ID))
            {
                frvProductDetail.DataSource = Product_BAL.Get_ProductAsTable("Pro_ID=" + product_ID, "");
                frvProductDetail.DataBind();
                if (!string.IsNullOrEmpty(Request.QueryString["Cate_ID"]))
                {
                    DataList2.DataSource = Product_BAL.Get_ProductAsPaging(1, 6, "Pro_ID DESC", "*", "Cate_ID=" + Request.QueryString["Cate_ID"] + "AND Pro_ID<>" + product_ID, "");
                    DataList2.DataBind();
                }
                else
                {
                    DataList2.DataSource = Product_BAL.Get_ProductAsPaging(1, 6, "Pro_ID DESC", "*", "Pro_ID<>" + product_ID, "");
                    DataList2.DataBind();
                }
                dtlComments.DataSource = Comments_BAL.Get_CommentsAsTable("Comments.Pro_ID=" + Request.QueryString["Product_ID"], "Com_ID DESC");
                dtlComments.DataBind();
            }
        }

    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("Basket.aspx?Product_ID=" + Request.QueryString["Product_ID"]);
    }

    protected void btnSend_Click(object sender, EventArgs e)
    {
        Comments comment = new Comments();
        comment.Pro_ID = int.Parse(Request.QueryString["Product_ID"]);
        comment.Com_Desc = txtcontent.Text;
        comment.Com_Title = txtEmail.Text;
        comment.Com_Status = true;

        Comments_BAL.Insert_Comments(comment);
        dtlComments.DataSource = Comments_BAL.Get_CommentsAsTable("Comments.Pro_ID=" + Request.QueryString["Product_ID"], "Com_ID DESC");
        dtlComments.DataBind();
        txtcontent.Text = txtEmail.Text = "";
    }    
}
